#字典
# dictionary三种创建方式
# 1.直接建key:value（已知所有的key:value）
# key起名规则：不可变的数据类型可以作为key：str,number,tuple

info = {
    "first":"taylor swift",
    "second":"fearless",
    "third":"speak now"
}

print(info)

# 2、先建个空字典，然后加值进去（有未知的，但是随着时间，慢慢知道了）
# info02[key]=value
info02 = {}
info02["fouth"]="red"
info02["fifth"]="1989"
print(info02)

# 3、dict(key01=value01,key02=value02...)
info03 = dict(sixth="reputation",seventh="lover",eighth="folkore")
print(info03)


# 字典查询：1、key存不存在？ 2、存在的话--查值value
print("eighth" in info03)
print(info03["eighth"])

#get()方法
print(info03.get("sixth"))

# value 可以使任一对象的数据
info04 = {
    "wing":{
        "name":"yongxin",
        "age":19,
        "info":[1,2,3]
    },
    "alice":"peishi",
    "nana":"xiaohui"
}
print(info04["wing"]["info"][1])

#update()
info05 = {"Python":"Thursday,6:45-8:55",
          "API":"Wednesday,6:45-8:55"
        }
print(info05)
info05.update({"Python":"Wednesday,6:45-8:55","API":"Thursday,6:45-8:55"})
print(info05)

#clear()
info06 = {"wing":19,"alice":20}
print(info06)
info06.clear()
print(info06)

#items(),keys(),values()
info = {
    "first":"taylor swift",
    "second":"fearless",
    "third":"speak now"
}
print(info.items())
print(info.keys())
print(info.values())

#pop(),popitem()
info07 = {"wing":1,"alice":2}
num = info07.pop("alice")
print(num)
print(info07)
print(info07.popitem())
print(info07)

#setdefault()
dict = {'runoob': '菜鸟教程', 'google': 'Google 搜索'}
print(dict.setdefault("taobao"))
print(dict)
print(dict.setdefault("Tmall","天猫"))
print(dict)

#字典的复制
a = {1,2,3}
b = a.copy() #深拷贝 源字典的改变不会影响它
c = a #浅拷贝 随着原字典的变化而变化
print(b,c)
a.update({4})
print(a,b,c)

#字典循环
wing = {"name":"wing","age":19,"job":"student"}
for k in wing:
    value = wing.get(k)
    print(k,value)

